package net.cloudcodex.shared;

/**
 * Message type : Action, OFF, DiceRoll
 */
public enum MessageType {

	ACTION("A"), OFF("O"), DICEROLL("D");

	/**
	 * Code.
	 */
	private final String code;

	/**
	 * @return the code.
	 */
	public String getCode() {
		return code;
	}

	/**
	 * @param code code.
	 */
	private MessageType(String code) {
		this.code = code;
	}
	
	/**
	 * Get a MessageType from a code (ie : from datastore).
	 * @param code code to map.
	 * @return message type.
	 */
	public static MessageType getMessageType(String code) {
		if(code == null) {
			return null;
		}
		for(MessageType type : values()) {
			if(type.getCode().equals(code)) {
				return type;
			}
		}
		return null;
	}
}
